<template>
	<div class="diglog-info streetEdit projectDialog">
		<el-dialog title="编辑" :visible.sync="dialogVisible" size='small'>
			<el-tabs>
				<el-tab-pane label="进展情况">
					<el-form :model="dataAll" :rules="rules" ref="dataAll" label-width="0" class="demo-ruleForm">
						<div v-if="dataAll" class="zui-noFloat">
							<el-row :gutter="80">
								<el-col :span="24">
									<el-form-item prop="progressSituation">
										<div class="content">
											<my-tooltip text="进展情况"></my-tooltip>
											<div class="desc-input">
												<el-input v-model="dataAll.progressSituation" type="textarea" placeholder="请输入进展情况"></el-input>
											</div>
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item>
										<div class="content">
											<my-tooltip text="上报单位"></my-tooltip>
											<el-select class="desc-input" v-model="dataAll.inputUnit" @change="changeValue" multiple placeholder="请选择">
												<el-option v-for="item in unitList" :key="item.id" :label="item.name" :value="item.id">
												</el-option>
											</el-select>
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="12">

								</el-col>
								<el-col :span="12">
									<el-form-item>
										<div class="content">
											<my-tooltip text="任务状态"></my-tooltip>
											<el-select class="desc-input" v-model="dataAll.status" placeholder="请选择">
												<el-option v-for="item in statusList" :key="item.id" :label="item.name" :value="item.id">
												</el-option>
											</el-select>
										</div>
									</el-form-item>
								</el-col>
							</el-row>
							<div style="text-align:left; margin-left:100px;">
								<el-button type="primary" @click="upate('dataAll')" style="width:130px">保存</el-button>
								<el-button @click="dialogVisible = false" style="width:130px;margin-left:20px">取消</el-button>
							</div>
						</div>
					</el-form>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>
	</div>
</template>
<script>
	export default {
		props: ['showDialogId'],
		created() {
			this.ajax({
				url: 'tDictionary/selectDictionaryByCode',
				data: {
					code: 'P1'
				}
			}).then(data => {
				this.unitList = data;
				this.ajax({
					url: 'tDictionary/selectDictionaryByCode',
					data: {
						code: 'P2'
					}
				}).then(data => {
					this.statusList = data;
					this.queryInfo();
				})
			})

		},
		mounted() {

		},
		watch: {
			dialogVisible(val) {
				this.$emit('update:showDialog', val)
			}
		},
		data() {
			return {
				dialogVisible: true, //弹出框隐藏显示
				options: [],
				value: '',
				unitList: [],
				statusList: [],
				dataAll: {},
				areaList: [],
				rules: {
					progressSituation: [{
						required: true,
						message: '进展情况不能为空',
						trigger: 'blur'
					}],
					//					inputUnit: [{
					//						required: true,
					//						message: '上报单位不能为空',
					//						trigger: 'change'
					//					}]
				},
			}
		},
		methods: {
			show(row) {
				this.dialogVisible = !this.dialogVisible
			},
			queryInfo() {

				this.ajax({
					url: 'tProjectSupervisor/selectProjectSupervisorById',
					data: {
						id: this.showDialogId
					}
				}).then(data => {
					if(data[0].inputUnit) {
						data[0].inputUnit = this.formateData(data[0].inputUnit);
					}else{
						data[0].inputUnit=[];
					}
					if(typeof data[0].status == 'number') {
						data[0].status = parseInt(data[0].status);
					}
					this.dataAll = data[0]
				})
			},
			formateData(responseUnits){
				var selectunits=[];
				var responseunits=responseUnits.split(',');
				for(var i=0;i<responseunits.length;i++){
					if(responseunits[i]){
						selectunits.push(parseInt(responseunits[i]));
					}
				}
				return selectunits;
			},
			upate(formName) {
				this.$refs[formName].validate((valid) => {
					if(this.dataAll.inputUnit.length>=1){
						this.dataAll.inputUnit=this.dataAll.inputUnit.join(',');
					}else{
						this.dataAll.inputUnit="";
					}
					if(valid) {
						this.ajax({
							url: 'tProjectSupervisor/editProjectSupervisor',
							type: 'post',
							data: this.dataAll,
						}).then(data => {
							/*向上传递修改成功的信息*/
							this.eventBus.$emit('streetUpdate')
							this.dialogVisible = false
						})
					}
				});
			},
			changeValue(){
				//console.log(this.dataAll.inputUnit)
				//debugger
			}
		},
		components: {

		}
	}
</script>
<style lang="less">
	.streetEdit .el-form-item__error {
		top: 35px;
		left: 100px;
	}
	
	.streetEdit .el-form-item {
		min-height: 50px;
		margin-bottom: 5px;
	}
</style>
<style scoped lang="less">
	.zui-noFloat .el-col {
		float: none;
		display: inline-block;
		margin-right: -4px;
		vertical-align: top;
	}
	
	.projectDialog .desc-input {
		width: 70%;
		float: left;
	}
	.el-tag .el-icon-close {
    right: -5px !important;
}
</style>